{% layout = 'layout_base.html' %}

<div class="d-flex justify-content-center">
    <div class="card shadow" style="width: 300px; margin-top: 5%">
        <div class="card-body text-center">
            <img src="/www/favicon.ico" width="64px" height="64px" class="mb-1">
            <h1>团队协作系统</h1>
            <small>MAKE SOMETHING REAL TOGETHER</small><hr>

            <div id="err"></div>

            <form class="form" id="form-login" action="/user/login/do_login" method="POST">
                <div class="form-group">
                    <input type="text" class="form-control" name="account" placeholder="帐号" required autofocus>
                </div>
                <div class="form-group">
                    <input type="password" class="form-control" name="pswd" placeholder="登录密码" required>
                </div>
                <div class="form-check text-left">
                    <input type="checkbox" class="form-check-input" name="remember_me" id="remember_me" checked>
                    <label class="form-check-label" for="remember_me">一个月内自动登录</label>
                </div>
                <hr>
                <div class="form-group">
                    <button type="submit" class="btn btn-primary">登  录</button>
                </div>
                <a href="/user/login/forget_pswd">忘记密码</a>
            </form>
        </div>
    </div>
</div>

<script>

$('#form-login').on('submit', function(e) {
    e.preventDefault();

    $.ajax({
        url: '/user/login/do_login',
        type: 'POST',
        data: new FormData(document.getElementById('form-login')),
        dataType: 'json',
        processData: false,
        contentType: false,
        cache: false,
        success: function(rsp) {
            if (rsp.ok) {
                location.href = '/dashboard/tasks/';
            } else {
                showError('#err', '登录失败', rsp.err_msg);
            }
        }
    });
})

</script>